<%@ page contentType="text/html;charset=utf-8"%>
<%@ page
 import="java.io.*, java.sql.*, java.util.*, java.text.*, napal.*, util.*, napal.*,java.util.ArrayList
 "%>
<%@ page import="org.apache.ibatis.*"%>
<%@ page import="java.util.Date"%>

<%
 request.setCharacterEncoding("utf-8");
%>
<%@ include file="./Header.jsp"%>
   </td>
  </TR>
  <TR HEIGHT="100">
  <td>
  
 <a href="giguan.jsp" class="btn btn-link btn-small">기자재관리<br></a>
>  기자재등록<br><br><br>
 
 <form method="post">
<table class="table table-bordered">
 <%String selectedCategory = request.getParameter("select01");
 String selectedCategory1 = request.getParameter("select02");
 int mo1=0;
 String mng = (String)session.getAttribute("managerID");

	if(mng==null){ %>
	<script language=javascript>
				self.window.alert("권한이 없습니다.");
				location.href="Main.jsp?";
			</script>
<%}
	
 
  %> <%ArrayList array = new ArrayList();
  int de1=0;

       
          if ("소프트웨어공학과".equals(selectedCategory))
           de1 = 1;
          else if ("정보통신공학과".equals(selectedCategory))
           de1 = 2;
          else if ("멀티미디어시스템공학과".equals(selectedCategory))
           de1 = 3;
          else if ("글로컬IT학과".equals(selectedCategory))
           de1 = 4;
          else if ("디지털컨텐츠학과".equals(selectedCategory))
           de1 = 5;
          else if ("신문방송학과".equals(selectedCategory))
           de1 = 6;
          else if ("경영학부".equals(selectedCategory))
           de1 = 7;
          else if ("사회과학부".equals(selectedCategory))
           de1 = 8;
          else if ("일어일본학과".equals(selectedCategory))
           de1 = 9;
          else if ("영어학과".equals(selectedCategory))
           de1 = 10;
          else if ("신학과".equals(selectedCategory))
           de1 = 11;
          else if ("사회복지학과".equals(selectedCategory))
           de1 = 12;
          else if ("중어중국학과".equals(selectedCategory))
           de1 = 13;
          String[] a;  
          String st = request.getParameter("st");
          String date1 = request.getParameter("date1");
          String money = request.getParameter("money");
          String sang = request.getParameter("sang");
          String yn = request.getParameter("yn");
          String bigo = request.getParameter("bigo");
          String mo = request.getParameter("select02");
          String errMsg="";
          String su = request.getParameter("su");
          int su1=0;
          if(su!=null){
       	  su1=Integer.parseInt(su);
          }

          
          if (st == null) {
        		st="";
        		date1="";
        		money="";
        		sang="";
        		yn="";
        		bigo="";
        	}	
          
        if ("등록하기".equals(request.getParameter("cmd"))) {

            for(int i=0; i<su1; i++){
                if(request.getParameter("num"+i).equals("")){
               	 errMsg="기자재 관리번호를 입력하세요";
              		%>
              			<font color="red"> <%=errMsg%>
              			</font>
              			
              		<%break;}
                else{
               	 String iu = request.getParameter("num"+i);
                    array.add(iu);
                }
               }
        
         if(mo.equals("선택안함")){
      		errMsg="모델을 선택하세요";
      		%>
      			<font color="red"> <%=errMsg%>
      			</font>
      		<%}
        
    	else  if(su1==0){
  			errMsg="기자재관리번호 등록할 개수를 입력하세요.";
  		%>
  				<font color="red"> <%=errMsg%>
  				</font>
  			<%}
        
  		else  if(de1==0){
  			errMsg="학과를 선택하세요";
  		%>
  				<font color="red"> <%=errMsg%>
  				</font>
  			<%}
  		
  		else if(st==""){
  		errMsg="보관사용처를 입력하세요";
  		%>
  			<font color="red"> <%=errMsg%>
  			</font>
  		<%}
  		
  		else if(date1==""){
  			errMsg="구매날짜를 입력하세요";
  		%>
  		<font color="red"> <%=errMsg%>
  			</font>
  		    <%}
    	  
  		else if(date1.length()!=10){
  			errMsg="구매날짜를 형식을 정확히 입력하세요";
  		%>
  		<font color="red"> <%=errMsg%>
  			</font>
  		    <%}
  		
  		else if(money==""){
  			errMsg="구매금액을 입력하세요";
  		%>
  		<font color="red"> <%=errMsg%>
  			</font>
  		    <%}
  		
  		else if(sang==""){
  			errMsg="기가재상태를 입력하세요";
  		%>
  		<font color="red"> <%=errMsg%>
  			</font>
  		    <%}
  		
  		else if(yn==""){
  			errMsg="	공개여부를 입력하세요";
  		%>
  		<font color="red"> <%=errMsg%>
  			</font>
  		    <%}
  		    
  		  else if(bigo==""){
  			  errMsg="비고를 입력하세요";
  		  %>
  		<font color="red"> <%=errMsg%>
  			</font>
  		    <%}
  		  else{
  			int mon=Integer.parseInt(money);
         Model e=RentalHome.modelenroll(selectedCategory1);
         int m=e.get모델번호();
         for(int i=0; i<array.size(); i++){
          String gi =(String)array.get(i);
         RentalHome.insertEq(gi, de1, m, st, sang, date1, mon, yn,
           bigo);}
         %><script language=javascript>
       self.window.alert("기자재를 등록하였습니다.");
       location.href="giguan.jsp";
    </script>
         
       <% }
        }
       
      %>
<tr>      
       <td>기자재 수량입력</td>
       <%session.setAttribute("sur",request.getParameter("su"));%>
       <Td><input type="text" name="su" placeholder="Text input" value=<%=su1%>>
       </td>
       <td> <INPUT name="cmd5" class="btn btn-inverse" TYPE="submit" VALUE="관리번호 입력하기"></td>
       </tr>
       <% 
         
       if ("관리번호 입력하기".equals(request.getParameter("cmd5"))) { 
    	
    			String su2 = request.getParameter("su");
        int su3=Integer.parseInt(su2);
      
        %><input type="hidden" name="su1234" values="<%=su3%>"><%
         for(int i=0; i<su3; i++){%>
     <tr class="success">
       <td>기자재관리번호</td>
       <Td><input type="text" name="num<%=i%>" placeholder="Text input"></td>
       <td>관리번호<%=i+1%></td>
      </tr>
      <% }}
       %>
    
      <tr>
      <td>모델</td>
       <td><select name="select02">
         <OPTION value="선택안함">모델선택</OPTION>

         <%
          for (Model g : RentalHome.model()) {
         %>
         <OPTION VALUE="<%=g.get모델명()%>"
          <%=g.get모델명().equals(selectedCategory1) ? "selected"
      : ""%>><%=g.get모델명()%></OPTION>

         <%
          }
         %>
     </SELECT></td>
       <Td>해당 모델이 없으면 새로등록하세요.</td>
       </tr>
      
      
      <tr>
      <td>학과</td>
       <td><select name="select01">
         <OPTION VALUE='학과선택'>학과선택</OPTION>
         <OPTION VALUE="소프트웨어공학과"<%="소프트웨어공학과".equals(selectedCategory) ? "selected" : ""%> >소프트웨어공학과</OPTION>
         <OPTION VALUE="정보통신공학과"<%="정보통신공학과".equals(selectedCategory) ? "selected" : ""%> >정보통신공학과</OPTION>
         <OPTION VALUE="멀티미디어시스템공학과"<%="멀티미디어시스템공학과".equals(selectedCategory) ? "selected" : "" %>>멀티미디어시스템공학과</OPTION>
         <OPTION VALUE="글로컬IT학과"<%="글로컬IT학과".equals(selectedCategory) ? "selected" : "" %>>글로컬IT학과</OPTION>
         <OPTION VALUE="디지털컨텐츠학과"<%="디지털컨텐츠학과".equals(selectedCategory) ? "selected" : "" %>>디지털컨텐츠학과</OPTION>
         <OPTION VALUE="신문방송학과"<%="신문방송학과".equals(selectedCategory) ? "selected" : ""%> >신문방송학과</OPTION>
         <OPTION VALUE="경영학부"<%="경영학부".equals(selectedCategory) ? "selected" : "" %>>경영학부</OPTION>
         <OPTION VALUE="사회과학부"<%="사회과학부".equals(selectedCategory) ? "selected" : "" %>>사회과학부</OPTION>
         <OPTION VALUE="일어일본학과"<%="일어일본학과".equals(selectedCategory) ? "selected" : "" %>>일어일본학과</OPTION>
         <OPTION VALUE="영어학과"<%="영어학과".equals(selectedCategory) ? "selected" : "" %>>영어학과</OPTION>
         <OPTION VALUE="신학과"<%="신학과".equals(selectedCategory) ? "selected" : ""%> >신학과</OPTION>
         <OPTION VALUE="사회복지학과"<%="사회복지학과".equals(selectedCategory) ? "selected" : ""%> >사회복지학과</OPTION>
         <OPTION VALUE="중어중국학과"<%="중어중국학과".equals(selectedCategory) ? "selected" : "" %>>중어중국학과</OPTION></td>
         <td></td>
      </tr>
       
      <tr>
   <td>보관사용처</td>
   <td><input type="text" name="st"  value=<%=st%>></td>
   <td></td>
  </tr>
  <tr>
   <td>구매날짜</td>
   <td><input type="text"  name="date1" value=<%=date1%>></td>
   <td>( 형식 : 2000-01-01 )</td>
  </tr>
  <tr>
   <td>구매금액</td>
   <td><input type="text"  name="money" value=<%=money%>></td>
   <td>( 형식 : 2000000 )</td>
  </tr>
  <tr>
   <td>기자재상태</td>
   <Td><input type="text" name="sang" value="대여가능"></td>
   <td></td>
  </tr>
  <tr>
   <td>공개여부</td>
   <td><input type="text" name="yn"  value="공개"></td>
   <td>( 공개/비공개 )</td>
  </tr>
  <tr>
   <td>비고</td>
   <td><input type="text"  name="bigo" value="없음"></td>
   <td></td>
  </tr>
  
 </table>
      
    
<INPUT name="cmd" class="btn btn-inverse" TYPE="submit" VALUE="등록하기"> 
  </form>
     
 </TD>
</TR>

<TR HEIGHT="100">
<TD><%@ include file="./bottom.jsp"%></TD> 
</TR>
</TABLE>
</body>
</html>
